package test.com.adapter;

import java.util.List;

import test.com.R;
import test.com.domain.Cuisine;
import test.com.util.PictureTask;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MenuListAdapter extends BaseAdapter{

	private List<Cuisine> list;
	private Context mContext;
	private ViewHolder holder;
	
	public MenuListAdapter(Context mContext, List<Cuisine> list) {
		this.mContext = mContext;
		this.list = list;
	}
	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if(convertView==null || convertView.getTag()==null){
			convertView=LayoutInflater.from(mContext).inflate(R.layout.menulist,null);
			holder = new ViewHolder();
			holder.menuImage=(ImageView) convertView.findViewById(R.id.menuImage);
			holder.menuamount=(TextView) convertView.findViewById(R.id.menuamount);
			holder.menuname=(TextView) convertView.findViewById(R.id.menuname);
			convertView.setTag(holder);
			}else{
				holder=(ViewHolder) convertView.getTag();
			}
			holder.menuImage.setTag(new String[]{list.get(position).getCuisine_pic()});
			new PictureTask(mContext).execute(holder.menuImage);
		holder.menuname.setText(list.get(position).getCuisine_name());
		holder.menuamount.setText(list.get(position).getDish_count()+"");
		return convertView;
	}

	class ViewHolder{
		public ImageView menuImage;
		public TextView menuname,menuamount;
	}
}
